﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
using DTO;
//0712452
namespace DAO
{
    public class NapTienDAO
    {
        public static void ThemGiaoDich(GiaoDichDTO gdDto, PhieuNapTienDTO napTienDto, KhachHangDTO khachHangDto, string nhanVien, ref double LePhi)
        {
            SqlConnection cnn = KetNoiCSDL.TaoKetNoi();
            SqlCommand cmd = new SqlCommand("sp_Lay_phi_nap", cnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@Ma_TK", SqlDbType.Char);
            cmd.Parameters.Add("@So_tien", SqlDbType.Money);
            cmd.Parameters.Add("@MaNV", SqlDbType.VarChar);
            cmd.Parameters.Add("@HoTenNguoiNhan", SqlDbType.NVarChar);
            cmd.Parameters.Add("@HoTenNguoiGui", SqlDbType.NVarChar);
            cmd.Parameters.Add("@DiaChiNguoiGui", SqlDbType.NVarChar);

            cmd.Parameters["@Ma_TK"].Value = gdDto.MaTK;
            cmd.Parameters["@So_tien"].Value = napTienDto.SoTien ;
            cmd.Parameters["@MaNV"].Value = nhanVien;
            cmd.Parameters["@HoTenNguoiNhan"].Value = khachHangDto.HoTen ;
            cmd.Parameters["@HoTenNguoiGui"].Value = napTienDto.HoTenNguoiGui ;
            cmd.Parameters["@DiaChiNguoiGui"].Value = napTienDto.DiaChiNguoiGui ;
            cnn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            
            try
            {
                if (dr.Read())
                {
                    LePhi = double.Parse(dr["LePhi"].ToString());
                }
                cnn.Close();
            }
            catch (Exception ex)
            {
                if (cnn.State == ConnectionState.Open)
                    cnn.Close();
                throw ex;
            }
        }
    }
}
